package com.example.dishit.view.createdish;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;

import com.example.dishit.model.dish.DishData;

public class RestaurantArrayAdapter extends ArrayAdapter<DishData> {
    private final Context context;
    private final List<DishData> dishes;
    
    public RestaurantArrayAdapter(Context context, List<DishData> dishes) {
        super(context, android.R.layout.simple_spinner_item, dishes);
        this.context = context;
        this.dishes = dishes;
    }
    
    @Override
    public View getView(int position, final View convertView, final ViewGroup parent) {
        final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View dishView = inflater.inflate(android.R.layout.simple_spinner_item, parent, false);
        
        // TEXT
        final DishData dish = dishes.get(position);
        TextView textView = (TextView) dishView.findViewById(android.R.id.text1);
        textView.setText(dish.getRestaurantName());
        
        return dishView;
    }
    
    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View dishView = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
        
        // TEXT
        final DishData dish = dishes.get(position);
        final CheckedTextView textView = (CheckedTextView) dishView.findViewById(android.R.id.text1);
        textView.setText(dish.getRestaurantName());
        
        return dishView;
    }
}
